package controller;

import java.io.IOException;

import base.Communication;
import base.View;

import communication.BluetoothCommunication;

import exceptions.InitializedException;

public class MessengerController {
	
	private final View view;
	private Communication communication;
	
	public MessengerController(View view) {
		this.view = view;
		communication = new BluetoothCommunication();
	}
	
	public void startControl() {
		try {
			communication.init();
		} catch (InitializedException e) {
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}
	
	public void runTest() {
		try {
			communication.init();
			String[] urls = communication.search();
			if (urls.length > 0) {
				communication.send(urls[0], "Test message from bluetooth messenger");
			}
//			communication.startReceiver(((BluetoothCommunication)communication).SEND_URL, new MessageListener() {
//				public void recieved(String msg) {
//					view.showMsg(null, msg);
//				}
//			});
		} catch (InitializedException e) {
			view.showMsg(null, e.getMessage());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
